/**
 * 
 */
package snippet.tree.editor;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.editor.FormEditor;

/**
 * @author amergey
 *
 */
public class Editor extends FormEditor {
	
	private boolean mDirty = false;

	/* (non-Javadoc)
	 * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
	 */
	@Override
	protected void addPages() {
		try {
			addPage(new EditorPage(this, "page", "main"));
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
	 */
	@Override
	public void doSaveAs() {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
	 */
	@Override
	public boolean isSaveAsAllowed() {
		// TODO Auto-generated method stub
		return false;
	}
	
	/**
	 * @see FormEditor#isDirty()
	 */
	@Override
	public boolean isDirty() {
		return mDirty;
	}
	
	/**
	 * <p>Forces the dirty state of the editor to the dirty state passed as a parameter.
	 * <p>IMPORTANT NOTE: this method must be used with extreme caution to prevent from
	 * loosing unsaved changes.
	 * @param pDirty dirty state
	 */
	public void setDirty(boolean pDirty) {
		mDirty=pDirty;
		firePropertyChange(PROP_DIRTY);
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		setDirty(false);
	}

}
